package com.fantasy.file;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

public class ReadTxt {

	public static String read(String txtpath) {
		StringBuffer result = new StringBuffer();
		Reader inputStream;
		try {
			inputStream = GetFileReader(txtpath);
			BufferedReader bufInputStream = new BufferedReader(inputStream);
			while (bufInputStream.ready()) {
				result.append((char) bufInputStream.read());
			}
			inputStream.close();
			bufInputStream.close();
		} catch (FileNotFoundException e) {
			System.err.println(e.getMessage() + ":::::::::::::" + ReadTxt.class);
			return "";
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result.toString();
	}
	
	public static BufferedReader GetBufferReader(String path){
		BufferedReader bufReader = null;
		try {
			bufReader = new BufferedReader(new FileReader(path));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return bufReader;
	}
	
	public static FileReader GetFileReader(String path) throws FileNotFoundException{
		FileReader reader = null;
		reader = new FileReader(path);
		return reader;
	}

	public static void main(String[] args) {
		String path = GetFolderAbsPath.getPath() + "/test.txt";
		System.out.println(path);
		System.out.println("************");
		System.out.println(read(path));
	}

}
